package com.pccw.oframework.dao.sqlt;

import java.util.List;

import org.apache.commons.lang.StringUtils;

import com.aotain.oframework.util.lang.StringUtil;

public class SqltUtil {

	public boolean isNull(Object o) {
		return o == null;
	}

	public boolean isNotNull(Object o) {
		return !isNull(o);
	}

	public boolean isNotBlank(String str) {
		return StringUtils.isNotBlank(str);
	}

	public boolean isBlank(String str) {
		return StringUtils.isBlank(str);
	}

	public boolean isInclude(boolean bool) {
		return bool;
	}

	/**
	 * check whether the search criteria indicates to perform a fuzzy query.
	 * 
	 * @param searchCriteria
	 * @return
	 */
	public boolean isFuzzyQuery(String searchCriteria) {

		if (StringUtils.isEmpty(searchCriteria))
			return false;
		if (searchCriteria.indexOf("%") != -1)
			return true;

		return false;
	}

	public boolean isEmptyList(List<Object> list) {
		return null == list || list.size() == 0;
	}

	public boolean equals(String s1, String s2) {
		return s1.equals(s2);

	}

	/**
	 * Add by Bi Chen(80425952) XA ODC
	 * 
	 * @param str
	 * @return
	 */
	public boolean notEquals(String s1, String s2) {
		return !s1.equals(s2);

	}

	public String toString(String str) {
		if (null == str)
			return "null";

		return "'" + str + "'";
	}

	private static final String COLNAMES_SEPARATOR = ",";

	public String handleColNames(String poName, String colNames) {
		if (StringUtil.isEmptyString(poName)) {
			return "";
		}
		if (StringUtil.isEmptyString(colNames)) {
			return "";
		}
		StringBuffer _colNames = new StringBuffer();
		String[] qlStrs = StringUtils.splitByWholeSeparator(colNames,
				COLNAMES_SEPARATOR);
		for (int i = 0; i < qlStrs.length; i++) {
			String ql = qlStrs[i];
			if (!StringUtil.isEmptyString(ql)) {
				if (i == 0)
					_colNames.append(String.format("%1$s.%2$s", poName, ql));
				else
					_colNames.append(String.format(", %1$s.%2$s", poName, ql));
			}
		}
		return _colNames.toString();
	}
}
